﻿--|--------------------------------------------------------------------------------
--| [GetEntityListByGameID] - Insert Procedure Script for Entity
--|--------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[GetEntityListByGameID]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) 
  DROP PROCEDURE [dbo].[GetEntityListByGameID]
GO

CREATE PROCEDURE [dbo].[GetEntityListByGameID]
(
	@GameID int
)
AS
	SET NOCOUNT ON

	SELECT
		E.ID,
		GE.[EntityID],
		GE.[GameID],
		GE.[ParentGameEntityID] ParentID,
		E.[Name],
		E.[Description],
		E.[TeamID],
		E.[EntityTypeID],
		ET.[Name] as [EntityTypeName],
		GE.[OrderNumber]
	FROM [Entity] E
	LEFT JOIN [EntityType] ET ON E.[EntityTypeID] = ET.[ID]
	JOIN [GameEntity] GE ON E.ID = GE.EntityID
	WHERE
		GE.[GameID] = @GameID
	ORDER BY [ParentGameEntityID], [OrderNumber]
GO
 